package cn.fay.chapter11;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Stack;

public class Test12 {
	public static void main(String[] args) {
		List<Integer> list1=new ArrayList<Integer>();
		Collections.addAll(list1, 0,1,2,3,4,5,6,7,8,9);
		List<Integer> list2=new ArrayList<Integer>(list1.size());
		//reverse1(list1, list2);
		//reverse2(list1, list2);
		//reverse3(list1, list2);
		//reverse4(list1, list2);
		//reverse5(list1, list2);
		
	}

	private static void reverse5(List<Integer> list1, List<Integer> list2) {
		Integer[] arr=new Integer[10];
		for (int i=9;i>=0;i--){
			arr[i]=list1.remove(0);
		}
		list2.addAll(Arrays.asList(arr));
		System.out.println(list2);
	}

	private static void reverse4(List<Integer> list1, List<Integer> list2) {
		while (!list1.isEmpty()) {
			list2.add(0, list1.remove(0));
		}
		System.out.println(list2);
	}

	private static void reverse3(List<Integer> list1, List<Integer> list2) {
		while (!list1.isEmpty()) {
			int i=list1.remove(list1.size()-1);
			list2.add(i);
		}
		System.out.println(list2);
	}

	private static void reverse2(List<Integer> list1, List<Integer> list2) {
		Iterator<Integer> iterator = list1.iterator();
		Stack<Integer> stack=new Stack<Integer>();
		while (iterator.hasNext()) {
			stack.push(iterator.next());
		}
		while (!stack.isEmpty()) {
			list2.add(stack.pop());
		}
		System.out.println(list2);
	}

	private static void reverse1(List<Integer> list1, List<Integer> list2) {
		ListIterator<Integer> listIterator=list1.listIterator(list1.size());
		while (listIterator.hasPrevious()) {
			int i=listIterator.previous();
			list2.add(i);
		}
		System.out.println(list1);
		System.out.println(list2);
	}

}
